﻿using System;
using Pantry.Business;

namespace Pantry.Web.Control
{
    public partial class ListTypeOfBusiness : System.Web.UI.UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            Fillter(textboxBusiness.Text,TextboxSIC.Text);
        }

        protected void Fillter(string businessname, string siccode)
        {
            if (businessname != null || siccode != null)
            {
                CollectionPager2.PageSize = 5;
                CollectionPager2.BindToControl = RepeaterBusiness;
                CollectionPager2.DataSource = new TypeOfBusinessBus().ReturnSearchValue(businessname, siccode);

                if (CollectionPager2.TotalRecords != 0)
                {
                    RepeaterBusiness.DataSource = CollectionPager2.DataSourcePaged;
                    RepeaterBusiness.DataBind();
                }
                else
                {
                    var dt = new TypeOfBusinessBus().ListAddressesToDataSet().Tables[0];
                    CollectionPager2.PageSize = 5;
                    CollectionPager2.BindToControl = RepeaterBusiness;
                    CollectionPager2.DataSource = dt.DefaultView;
                    RepeaterBusiness.DataSource = CollectionPager2.DataSourcePaged;
                    RepeaterBusiness.DataBind();
                }
            }

            else
            {
                var dt = new TypeOfBusinessBus().ListAddressesToDataSet().Tables[0];
                CollectionPager2.PageSize = 5;
                CollectionPager2.BindToControl = RepeaterBusiness;
                CollectionPager2.DataSource = dt.DefaultView;
                RepeaterBusiness.DataSource = CollectionPager2.DataSourcePaged;
                RepeaterBusiness.DataBind();
            }
        }

        protected void Search_Click(object sender, EventArgs e)
        {
            //Response.Redirect("ViewListTypeOfBusiness.aspx?TypeName=" + textboxBusiness.Text.Trim() + "&Code=" + TextboxSIC.Text.Trim() + "");
            Fillter(textboxBusiness.Text, TextboxSIC.Text);
        }
        protected void None_Click(object sender, EventArgs e)
        {
            textboxBusiness.Text = null;
            TextboxSIC.Text = null;
            Fillter(textboxBusiness.Text, TextboxSIC.Text);
        }
        protected void Clear_Click(object sender, EventArgs e)
        {
            textboxBusiness.Text = null;
            TextboxSIC.Text = null;
            
        }
    }
}